package com.kapcb.common.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * <a>Title: SwitchEnum </a>
 * <a>Author: kapcb <a>
 * <a>Description: 通用状态枚举 <a>
 *
 * @author Kpacb
 * @version 1.0
 * @date 2024/5/1 14:48
 * @since 1.0
 */
public enum SwitchEnum implements IntArrayValuable {

    /**
     * 关闭
     */
    OFF(0, "关闭"),

    /**
     * 开启
     */
    ON(1, "开启");

    private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SwitchEnum::getStatus).toArray();

    /**
     * 状态值
     */
    private final Integer status;
    /**
     * 状态名
     */
    private final String name;

    SwitchEnum(Integer status, String name) {
        if (status == null || StringUtils.isBlank(name)) {
            throw new IllegalArgumentException("通用状态枚举参数错误，请检查代码!");
        }
        this.status = status;
        this.name = name;
    }

    public Integer getStatus() {
        return this.status;
    }

    @Override
    public int[] array() {
        return ARRAYS;
    }

    public static boolean isOn(Integer status) {
        return ON.status.equals(status);
    }

    public static boolean isOff(Integer status) {
        return OFF.status.equals(status);
    }

}
